package com.jiuyin.dianjing.db.helper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.jiuyin.dianjing.db.table.SearchHistoryColumn;
import com.jiuyin.dianjing.util.LogUtil;

import static com.jiuyin.dianjing.constant.HelperConstant.DB_TREATED_DEF;

/**
 * @author Administrator
 */
public class DataHelper extends SQLiteOpenHelper {
    private static final String SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS ";
    private static final String SQL_AUTOINCREMENT_KEY = " INTEGER PRIMARY KEY AUTOINCREMENT";
    private static final String SQL_KEY_DEFAULT = " INTEGER DEFAULT " + DB_TREATED_DEF;
    private static final String SQL_TEXT = " TEXT";
    private static final String SQL_TEXT_PRIMARY_KEY = " TEXT UNIQUE";
    private static final String SQL_COMMA = ",";
    private static final String SQL_DROP_TABLE = "DROP TABLE IF EXISTS ";
    private static final String DATABASE_NAME = "order_product.db";
    private static final int VERSION_1 = 1;
    private static final int VERSION_2 = 2;
    private static final int VERSION_3 = 3;
    private static final int VERSION = VERSION_1;
    private static String TABLE_SEARCH_HISTORY = SQL_CREATE_TABLE + SearchHistoryColumn.TABLE_NAME
            + " (" + SearchHistoryColumn._ID + SQL_AUTOINCREMENT_KEY + SQL_COMMA
            + SearchHistoryColumn.CONTENT + SQL_TEXT_PRIMARY_KEY
            + ");";

    public DataHelper(Context context) {
        super(context, DATABASE_NAME, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(TABLE_SEARCH_HISTORY);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        LogUtil.logCommon("onUpgrade oldVersion " + oldVersion + " newVersion " + newVersion);
//        if (VERSION_2 == oldVersion) {
//            db.execSQL(TABLE_SEARCH_HISTORY);
//        }
    }
}
